﻿using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour
{
	public const int maxProjectiles = 5;
	private const int sheepWin = 50;
	private const int sheepLose = 10;
	private const int level_change = 5;
	private const float speed_up = 0.9f;
	private const float speed_dn = 1.25f;
	private const int add_spawn_multiplier = 2;

    public static float spawnRate;
    public static int count;
	public static int numProjectiles;
	public static int sheepDead;
	public static int sheepCollected;
    private static int diff_inc;

    // Use this for initialization
    void Start()
    {
		spawnRate = 3;
        count = 0;
		numProjectiles = 0;
		sheepDead = 0;
		sheepCollected = 0;
        diff_inc = -1;

        Instantiate(Resources.Load("SheepSpawn"), this.transform.position, Quaternion.identity);
    }

    // Update is called once per frame
    void Update()
    {
        DifficultySetting();

        if (sheepCollected >= sheepWin)
        {
            //Load win screen
            Application.LoadLevel(4);
        }
        else if (sheepDead >= sheepLose)
        {
            // Load lose scene
            Application.LoadLevel(3);
        }
    }


    void DifficultySetting()
    {
        if (sheepCollected % (add_spawn_multiplier * level_change) == 0 && sheepCollected > 0 && diff_inc != sheepCollected)
        {
            diff_inc = sheepCollected;
            spawnRate *= speed_dn;
            Instantiate(Resources.Load("SheepSpawn"), this.transform.position, Quaternion.identity);
        }
        else if(sheepCollected % level_change == 0 && sheepCollected > 0 && diff_inc != sheepCollected)
        {
            diff_inc = sheepCollected;
            spawnRate *= speed_up;
        }
    }
}
